package com.customer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 2 * @Author: xy
 * 3 * @Date: 2021/10/12 上午 11:35:58
 */
@Service
public class CustomerLogin {
    @Autowired
    private RedisService redisService;

    public int login(String phone, String code) {
        String redisCode = (String) redisService.hmget(phone).get("code");
        if (redisCode == null) {
            return -1;
        }
        if (redisCode.length() != code.length()) {
            return -1;
        }
        System.out.println(redisCode);
        char[] c1 = redisCode.toCharArray();
        char[] c2 = code.toCharArray();

        //失败次数
        int count = 0;
        for (int i = 0; i < c1.length; i++) {
            for (int j = 0; j < c1.length; j++) {
                if (c1[i] != c2[i]) {
                    count++;
                    return count;
                }
            }
        }
        return count;
    }
}

